/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * pnHome.java
 *
 * Created on Sep 5, 2010, 1:13:52 PM
 */
package Gui;

import BusinessLogic.Statistics;
import DTO.Manager;
import DTO.Zone;
import java.awt.Color;
import java.awt.FlowLayout;
import java.util.Vector;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 *
 * @author SONY
 */
public class pnStatistics extends javax.swing.JPanel {

    private Statistics statis;

    /** Creates new form pnHome */
    public pnStatistics() {
        initComponents();

        statis = new Statistics();

        statManager();
        statZone();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnStaManager = new javax.swing.JPanel();
        lblPowerAd = new javax.swing.JLabel();
        lblPowerMa = new javax.swing.JLabel();
        lblTotalMan = new javax.swing.JLabel();
        pnStaZone = new javax.swing.JPanel();
        lblTotalZone = new javax.swing.JLabel();
        lblTotalBooth = new javax.swing.JLabel();

        setBackground(new java.awt.Color(255, 255, 255));

        pnStaManager.setBackground(new java.awt.Color(255, 255, 255));
        pnStaManager.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Statistic Manager", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N
        pnStaManager.setLayout(null);

        lblPowerAd.setText("Power Administrator: ");
        pnStaManager.add(lblPowerAd);
        lblPowerAd.setBounds(40, 60, 110, 14);

        lblPowerMa.setText("Power Manager:");
        pnStaManager.add(lblPowerMa);
        lblPowerMa.setBounds(40, 90, 90, 14);

        lblTotalMan.setText("Total Manager : ");
        pnStaManager.add(lblTotalMan);
        lblTotalMan.setBounds(40, 30, 120, 14);

        pnStaZone.setBackground(new java.awt.Color(255, 255, 255));
        pnStaZone.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Statistic Zone", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N
        pnStaZone.setLayout(null);

        lblTotalZone.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lblTotalZone.setForeground(new java.awt.Color(0, 51, 255));
        lblTotalZone.setText("jLabel1");
        pnStaZone.add(lblTotalZone);
        lblTotalZone.setBounds(50, 30, 110, 14);

        lblTotalBooth.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lblTotalBooth.setForeground(new java.awt.Color(0, 51, 255));
        lblTotalBooth.setText("jLabel1");
        pnStaZone.add(lblTotalBooth);
        lblTotalBooth.setBounds(170, 30, 140, 14);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 597, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(0, 18, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(pnStaZone, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 560, Short.MAX_VALUE)
                        .addComponent(pnStaManager, javax.swing.GroupLayout.PREFERRED_SIZE, 560, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addContainerGap(19, Short.MAX_VALUE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 448, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(19, 19, 19)
                    .addComponent(pnStaManager, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(pnStaZone, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(22, Short.MAX_VALUE)))
        );
    }// </editor-fold>//GEN-END:initComponents

    public void statManager() {
        Vector<Manager> listManager = statis.loadManager();
        int totalMan = listManager.size();
        int powerAd = countPowerAd(listManager);
        int powerMa = totalMan - powerAd;

        lblTotalMan.setText("Total Manager : " + totalMan);
        lblPowerAd.setText("Power Administrator: " + powerAd);
        lblPowerMa.setText("Power Manager: " + powerMa);
    }

    public void statZone() {
        Vector<Zone> listZone = statis.loadZone();
        int totalBooth = statis.totalBooth();

        lblTotalZone.setText("Total Zone: " + listZone.size());
        lblTotalBooth.setText("Total Booth: "+ totalBooth);
        
        for (int i = 1; i <= listZone.size(); i++) {
            Zone z = listZone.get(i -1);
            int boothInZone = statis.BoothInZone(z.getIDzone());

            JLabel nameZone = new JLabel("Zone: " + z.getName() + "- Total Booth: " + z.getNumberBooth());
            JLabel booUsed = new JLabel("Number Booth was be rent: " + boothInZone);

            JPanel pnCon = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 5));
            pnCon.setBackground(Color.WHITE);

            pnStaZone.add(pnCon);
            pnCon.setBounds(50, i * 50, 200, 50);

            pnCon.add(nameZone);
            pnCon.add(booUsed);
        }
    }

    public int countPowerAd(Vector<Manager> listManager) {
        int count = 0;
        for (int i = 0; i < listManager.size(); i++) {
            Manager man = listManager.get(i);
            if (man.getPower() == 1) {
                count++;
            }
        }
        return count;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel lblPowerAd;
    private javax.swing.JLabel lblPowerMa;
    private javax.swing.JLabel lblTotalBooth;
    private javax.swing.JLabel lblTotalMan;
    private javax.swing.JLabel lblTotalZone;
    private javax.swing.JPanel pnStaManager;
    private javax.swing.JPanel pnStaZone;
    // End of variables declaration//GEN-END:variables
}
